package top.kwanghuee.shop.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: kwanghuee
 * @date: 2020/9/15 9:42
 */
@RestController
@RefreshScope // 动态刷新注解
public class NacosConfigController {
    
    @Autowired
    private ConfigurableApplicationContext applicationContext;
    
    @Value("${config.appName}")
    private String appName;

    @Value("${config.env}")
    private String env;
    
    @GetMapping("/nacos-config-test1")
    public String nacosConfigTest1(){
        return applicationContext.getEnvironment().getProperty("config.appName");
    }

    @GetMapping("/nacos-config-test2")
    public String nacosConfigTest2(){
        return appName;
    }

    @GetMapping("/nacos-config-test3")
    public String nacosConfigTest3(){
        return env;
    }
}
